prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
mandir = @mandir@
man1dir = ${mandir}/man1

CC = @CC@
XASM = xasm -q
INSTALL = ./install-sh
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644

CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
DEFS = @DEFS@ -DASAP -DSOUND
LIBS = @LIBS@
ASAP2WAV = asap2wav@EXEEXT@
XMMS_CFLAGS = @XMMS_CFLAGS@
XMMS_LIBS = @XMMS_LIBS@
XMMS_INPUT_PLUGIN_DIR = @XMMS_INPUT_PLUGIN_DIR@
XMMS_USER_PLUGIN_DIR = ${HOME}/.xmms/Plugins

ATARI800_SRC_DIR = ../atari800/src
COMMON_C = asap.c ${ATARI800_SRC_DIR}/cpu.c ${ATARI800_SRC_DIR}/mzpokeysnd.c ${ATARI800_SRC_DIR}/pokeysnd.c ${ATARI800_SRC_DIR}/remez.c
COMMON_H = asap.h asap_internal.h config.h players.h ${ATARI800_SRC_DIR}/cpu.h ${ATARI800_SRC_DIR}/mzpokeysnd.h ${ATARI800_SRC_DIR}/pokey.h ${ATARI800_SRC_DIR}/pokeysnd.h ${ATARI800_SRC_DIR}/remez.h
PLAYERS_OBX = players/cmc.obx players/mpt.obx players/rmt4.obx players/rmt8.obx players/tmc.obx players/tm2.obx

all: ${ASAP2WAV} asap-xmms

${ASAP2WAV}: asap2wav.c ${COMMON_C} ${COMMON_H}
	${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${DEFS} -I. -I${ATARI800_SRC_DIR} asap2wav.c ${COMMON_C} ${LIBS}

asap-xmms: libasap.so

libasap.so: xmms/libasap.c ${COMMON_C} ${COMMON_H}
	${CC} ${CFLAGS} ${XMMS_CFLAGS} ${LDFLAGS} -shared -fPIC -o $@ ${DEFS} -I. -I${ATARI800_SRC_DIR} xmms/libasap.c ${COMMON_C} ${LIBS} ${XMMS_LIBS}

players.h: raw2c.pl ${PLAYERS_OBX}
	perl raw2c.pl ${PLAYERS_OBX} >$@

players/cmc.obx: players/cmc.asx
	${XASM} -o $@ players/cmc.asx

players/mpt.obx: players/mpt.asx
	${XASM} -o $@ players/mpt.asx

players/rmt4.obx: players/rmt.asx
	${XASM} -d STEREOMODE=0 -o $@ players/rmt.asx

players/rmt8.obx: players/rmt.asx
	${XASM} -d STEREOMODE=1 -o $@ players/rmt.asx

players/tmc.obx: players/tmc.asx
	${XASM} -o $@ players/tmc.asx

players/tm2.obx: players/tm2.asx
	${XASM} -o $@ players/tm2.asx

install: install-asap2wav install-xmms

install-asap2wav: ${ASAP2WAV} asap2wav.1
	${INSTALL_PROGRAM} ${ASAP2WAV} ${bindir}/${ASAP2WAV}
	${INSTALL_DATA} asap2wav.1 ${man1dir}/asap2wav.1

uninstall-asap2wav:
	rm -f ${bindir}/${ASAP2WAV} ${man1dir}/asap2wav.1

install-xmms: libasap.so
	${INSTALL_PROGRAM} libasap.so ${XMMS_INPUT_PLUGIN_DIR}/libasap.so

uninstall-xmms:
	rm -f ${XMMS_INPUT_PLUGIN_DIR}/libasap.so

install-user: libasap.so
	${INSTALL_PROGRAM} libasap.so ${XMMS_USER_PLUGIN_DIR}/libasap.so

uninstall-user:
	rm -f ${XMMS_USER_PLUGIN_DIR}/libasap.so

clean:
	rm -f players.h ${ASAP2WAV} libasap.so

distclean: clean
	rm -f Makefile config.log config.status config.h configure config.h.in
	rm -rf autom4te.cache
